﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace skydream
{
        /// <summary>
        /// 
        /// </summary>
    public class Inihelp
    {
        #region 引用API函数
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        [DllImport("user32")]
        private static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);
        [DllImport("user32")]
        private static extern IntPtr AppendMenu(IntPtr hMenu, int wFlags, int wIDNewItem, string lpNewItem);
        #endregion 引用API函数
        /// <summary>
        /// 读取INi配置文件
        /// </summary>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <param name="inifileName"></param>
        /// <returns></returns>
        public static string getIniText(string section,string key,string inifileName)
        {
            StringBuilder temp = new StringBuilder(255);
            //获取串口设置参数
            GetPrivateProfileString(section, key, "", temp, 255, inifileName);
            string port = temp.ToString();
            return port;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="inifileName"></param>
        /// <returns></returns>
        public static long modifyIniText(string section,string key,string value,string inifileName)
        {
            long temp=WritePrivateProfileString(section, key, value, inifileName);
            return temp;
        }

    }
}
